import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

import { Plugin as importToCDN } from 'vite-plugin-cdn-import'
import viteCompression from 'vite-plugin-compression'
import { visualizer } from 'rollup-plugin-visualizer'

// https://vitejs.dev/config/
export default defineConfig({
  base: '/manage/',
  plugins: [
    importToCDN({
      modules: [
        {
          name: 'vue',
          var: 'Vue',
          path: 'https://cdn.staticfile.net/vue/3.2.38/vue.global.prod.min.js'
        },
        {
          name: '@fortawesome/fontawesome-free/js/all',
          var:  'fontawesomeFree',
          // path: 'https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.2.1/js/all.min.js'
          path: 'https://cdn.staticfile.net/font-awesome/6.2.1/js/all.min.js'
        },
        {
          name: 'jsoneditor',
          var:  'JSONEditor',
          path: 'https://cdn.staticfile.net/jsoneditor/9.10.4/jsoneditor.min.js',
          css:  'https://cdn.staticfile.net/jsoneditor/9.10.4/jsoneditor.min.css'
        },
        {
          name: 'echarts',
          var:  'echarts',
          path: 'https://cdn.staticfile.net/echarts/5.4.1/echarts.min.js'
        },
        {
          name: '@wangeditor/editor/dist/index.js',
          var:  'wangEditor',
          path: 'https://cdn.staticfile.net/wangeditor5/5.1.23/index.min.js',
          css:  'https://cdn.staticfile.net/wangeditor5/5.1.23/css/style.css'
        },
        {
          name: 'lodash',
          var: 'lodash',
          path: 'https://cdn.staticfile.net/lodash.js/4.17.21/lodash.min.js'
        },
        {
          name: 'element-plus',
          var: 'ElementPlus',
          path: 'https://cdn.staticfile.net/element-plus/2.4.3/index.full.min.js'
        }
      ]
    }),
    vue(),
    viteCompression({
      threshold: 204800
    }),
    visualizer()
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
      'nodepath': fileURLToPath(new URL('./node_modules', import.meta.url))
    }
  },
  server: {
    proxy: {
      "/web": {
        target: "http://127.0.0.1:8009"
      }
    }
  }
})
